$(document).ready(function () {

  autochange();
  /*	window.onload =function(){ //这段如果隐藏掉，会导致imac系统页面缩放时图片变形
          autochange();
      }*/
  window.onresize = function () {
    autochange();
  };

});


//修正手机端点击返回页面时，上一页面内容不刷新/不读取js导致显示错误
//var browserRule =/^.*((iPhone)|(iPad)|(Safari))+.*$/;
//
//if(browserRule.test(navigator.userAgent)){
//
//window.onpageshow =function(event){
//
//if(event.persisted){
//
//window.location.reload()}
//
//};
//
//}


<!--根据窗口大小调整-->
function autochange() {
  document.addEventListener('gesturestart', function (e) {
    e.preventDefault();
  });
  document.addEventListener('dblclick', function (e) {
    e.preventDefault();
  });
  document.addEventListener('touchstart', function (event) {
    if (event.touches.length > 1) {
      event.preventDefault();
    }
  });
  var lastTouchEnd = 0;
  document.addEventListener('touchend', function (event) {
    var now = (new Date()).getTime();
    if (now - lastTouchEnd <= 300) {
      event.preventDefault();
    }
    lastTouchEnd = now;
  }, false);


  var windowTop = 0; //初始话可视区域距离页面顶端的距离
  $('.iphone__screen').css({'position': 'static'});
  $('.nav--active').css({'position': 'absolute'});
  $(window).scroll(function () {
    //获取滚动条的滑动距离
    var scroH = $(this).scrollTop();
    //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离，就固定，反之就不固定
    var scrolls = $(this).scrollTop(); //获取当前可视区域距离页面顶端的距离
    //alert(scrolls + "|" + windowTop)


    var screen_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;


    page_height = $('.page').height();

    if (page_height - scrolls - screen_height < screen_height) {

      oo = 1 - (page_height - scrolls - screen_height) / screen_height;


      $('#footer').css({'opacity': '' + oo + ''});
    }


  });


  var screen_width = $(window).width();//window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  var screen_height = $(window).height(); // window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  //var w=$(".menu").width();


  var guide_height = $('#guide img').height();

  var guide_fix = (screen_height - guide_height) / 2;
  $('#guide img').css({'padding-top': '' + guide_fix + 'px', 'opacity': '1'});


  //rem计算
  var remPer = screen_width / 1920 * 100 * 0.625;
  //remValue=remPer/0.625/10
  //alert(remPer+"|"+remValue)
  if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
    //移动端不变化
  } else {
    if (remPer < 55) {
      remPer = 55;
    }//最小50%
    $('html').css({'font-size': '' + remPer + '%'});
  }


  $('.float_div').css({'height': '' + screen_height + 'px'});
  $('.cabbeen_top').css({'height': '' + screen_height + 'px'});
  $('.page_vip').css({'height': '' + screen_height + 'px'});


  if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || screen_width < 1000) {
    //移动端

    //首页轮播 拉动时显示完整
    if (screen_width / screen_height > 2000 / 2400) {
      $('#index .swiper-slide').css({'background-size': '100% auto'});
    } else {
      $('#index .swiper-slide').css({'background-size': 'auto 100%'});
    }


    //$(".index_cbxs").css({"height":""+screen_height+"px"})

    $('.index_cbxs').css({'height': '' + screen_height + 'px'});
    var index_cbxs_p_1_h = screen_height * 0.8;
    $('.index_cbxs .photo li:nth-child(1)').css({'height': +index_cbxs_p_1_h + 'px', 'margin-top': +screen_height * 0.1 + 'px'});
    $('.index_cbxs .photo li:nth-child(1)').css({'margin-left': '20%'});


    //首页 品牌

    /*$(".index_brand .grid").css({"height":+screen_height+"px"});
    $(".index_brand .grid figure").css({"height":+screen_height*0.25+"px"});
    $(".index_brand").css({"padding-top":"0"});*/


    //首页 品牌
    var index_brand_height = $('.index_brand ul').height();
    index_brand_fix = (screen_height - index_brand_height) / 2;
    $('.index_brand ul').css({'margin-top': +index_brand_fix + 'px'});

    //$(".index_brand ul li").css({"height":+screen_height*0.5+"px"});


    $('.index_about .left').css({'height': +screen_height / 2 + 'px'});


    //$(".index_news ul").css({"height":+screen_height+"px"});
    $('.index_news ul').css({'height': +screen_height + 'px', 'top': '0'});
    $('.index_news ul li').css({'height': +screen_height * 0.333333 + 'px', 'margin': '0', 'padding': '0'});
    $('.index_news ul li:nth-child(2)').css({'margin-bottom': '0'});


    //卡宾先生-移动端-顶部大图背景自动适应
    if (screen_width / screen_height > 750 / 1029) {
      $('.cabbeen_top').css({'background-size': '100% auto'});
    } else {
      $('.cabbeen_top').css({'background-size': 'auto 100%'});
    }


    //防疫
    //var fangyi_packing_height=$("#fangyi .fangyi_packing .packing_box .swiper-slide-2-mobile img").height();
    //fangyi_packing_box_height=fangyi_packing_height*1.8
    fangyi_packing_box_height = 400;
    $('#fangyi .fangyi_packing .packing_box').css({'height': +fangyi_packing_box_height + 'px'});
    $('#fangyi .fangyi_packing .packing_box dd').css({'height': +fangyi_packing_box_height + 'px'});
    //alert(fangyi_packing_box_height)


  } else {//桌面端

    //首页轮播 拉动时显示完整
    if (screen_width / screen_height > 2880 / 1440) {
      $('#index .swiper-slide').css({'background-size': '100% auto'});
    } else {
      $('#index .swiper-slide').css({'background-size': 'auto 100%'});
    }

    //首页--卡宾先生
    var cabbeen_txt_height = $('.index_cbxs .photo .content').height();
    cabbeen_txt_height_fix = cabbeen_txt_height + screen_height * 0.8;

    $('.index_cbxs').css({'height': '' + cabbeen_txt_height_fix + 'px'});
    $('#index .index_cbxs').css({'height': '' + screen_height + 'px'});

    //首页--卡宾先生图片展示
    //大图1

    $('.index_cbxs').css({'height': '' + screen_height + 'px'});
    var index_cbxs_p_1_h = screen_height * 0.9;
    $('.index_cbxs .photo li:nth-child(1)').css({'height': +index_cbxs_p_1_h + 'px', 'margin-top': +screen_height * 0.05 + 'px'});
    var index_cbxs_p_1_w = index_cbxs_p_1_h / 970 * 682;
    //682*970
    var index_cbxs_p_1_left = (screen_width - index_cbxs_p_1_w) / 2;
    $('.index_cbxs .photo li:nth-child(1)').css({'width': +index_cbxs_p_1_w + 'px', 'margin-left': +index_cbxs_p_1_left + 'px'});
    //小图2/3
    var index_cbxs_p_2_h = screen_height * 0.4;
    $('.index_cbxs .photo li:nth-child(2)').css({'height': +index_cbxs_p_2_h + 'px', 'margin-top': +screen_height * 0.3 + 'px'});
    var index_cbxs_p_2_w = index_cbxs_p_2_h / 970 * 682;
    //682*970
    var index_cbxs_p_2_left = index_cbxs_p_1_left + index_cbxs_p_1_w - 40;
    $('.index_cbxs .photo li:nth-child(2)').css({'width': '100%', 'left': +index_cbxs_p_2_left + 'px'});

    //首页 品牌
    $('.index_brand ul').css({'height': +screen_height / 2 + 'px', 'padding-top': +screen_height * 0.25 + 'px'});

    $('.index_brand ul li').css({'padding-top': +screen_height * 0.2 + 'px', 'height': +screen_height * 0.5 + 'px'});

    var about_detail_height = $('.about_detail .left').height();
    $('.about_detail .right').css({'height': +about_detail_height + 'px'});

    $('.index_footer').css({'height': +screen_height + 'px'});

    //首页-关于我们背景判断
    if (screen_width / 2 / screen_height > 956 / 1248) {
      $('.index_about .swiper-slide').css({'background-size': '100% auto'});
    } else {
      $('.index_about .swiper-slide').css({'background-size': 'auto 100%'});
    }

    //$(".index_about .swiper-slide").css({"height":"" + screen_height+ "px"});
    $('.index_about .left').css({'height': '' + screen_height + 'px'});


    //首页-新闻
    $('.index_news ul').css({'height': +screen_height * 0.7 + 'px', 'top': +screen_height * 0.15 + 'px'});
    var index_news_li_space = screen_width * 0.7 * 0.04;

    $('.index_news ul li:nth-child(1)').css({'height': +screen_height * 0.7 + 'px', 'margin-right': +index_news_li_space + 'px'});

    var index_news_li2_height = (screen_height * 0.7 - index_news_li_space) / 2;

    $('.index_news ul li:nth-child(2)').css({'width': '', 'height': +index_news_li2_height + 'px', 'margin-bottom': +index_news_li_space + 'px'});
    $('.index_news ul li:nth-child(3)').css({'height': +index_news_li2_height + 'px'});


    //

    $('.brand_shop .swiper-slide').css({'height': +screen_height * 0.9 + 'px'});


    //卡宾先生-移动端-顶部大图背景自动适应
    if (screen_width / screen_height > 1920 / 1440) {
      $('.cabbeen_top').css({'background-size': '100% auto'});
    } else {
      $('.cabbeen_top').css({'background-size': 'auto 100%'});
    }


    //卡宾先生视频
    $('.cabbeen_movie').css({'height': +screen_height + 'px'});
    //视频上下间距计算
    cb_movie_top = (screen_height - screen_width * 0.6 * 720 / 1280) / 2;
    $('.cabbeen_movie').css({'padding-top': +cb_movie_top + 'px'});

  }
}


function show(i) {
  i = document.getElementById(i);
  if (i.style.display == 'block') {
    i.style.display = 'none';
  } else {
    i.style.display = 'block';
  }
}


function show_float(i) {
  i = document.getElementById(i);
  i.style.display = 'block';
  //$(i).fadeIn()
}

function hide_float(i) {
  i = document.getElementById(i);
  i.style.display = 'none';
  //$(i).fadeOut()
}

$('.gotosmooth').click(function () {
  var href = $(this).attr('href');
  var pos = $(href).offset().top;
  $('html,body').animate({scrollTop: pos}, 1000);
  return false;
});




